name: Spider
on:
  workflow_dispatch:
jobs:
  build:
    name: TVSpider
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        os: [ "ubuntu-latest" ]
    steps:
      - name: Clone Base Repository
        uses: actions/checkout@v3
        with:
          repository: ${{ secrets.GH_PATH}}
          fetch-depth: 0
          token: ${{ secrets.GH_TOKEN}}

      - name: Clone TVSpider Repository
        uses: actions/checkout@v3
        with:
          repository: jadehh/TVSpider
          path: tmp
          fetch-depth: 0  # 显示所有提交的日志

      - name: Build JS Config
        run: |
          cp -r ./tmp ./code
          cd code
          pip install https://github.com/jadehh/pythonTools/releases/download/JadeV2.1.7/jade-2.1.7-py3-none-any.whl
          python build.py --aliToken "${{ secrets.ALI_TOKEN }}" --biliCookie "${{ secrets.BILI_COOKIE}}"
          python build.py --aliToken "${{ secrets.ALI_TOKEN }}" --biliCookie "${{ secrets.BILI_COOKIE}}" --is_18 True

      - name:  Commit JS Config files
        run: |
          git config --global user.email "${{ secrets.GT_EMAIL }}"
          git config --global user.name "${{ secrets.GT_ACTOR }}"
          checkname=$(git rev-list --max-parents=0 HEAD)
          git checkout  $checkname -b js  ##分支不存在用这个
          cp -r code/18_open_config.json ./
          cp -r code/18_tv_config.json ./
          cp -r code/open_config.json ./
          cp -r code/tv_config.json ./
          cp -r code/js/ ./
          cp -r code/lib ./
          cp -r code/README.md ./README.md
          cp -r code/resources ./
          git add 18_open_config.json
          git add 18_tv_config.json
          git add open_config.json
          git add tv_config.json
          git add resources
          git add js
          git add lib 
          git add README.md
          commit_msg="* 更新TVConfig和OpenConfig"
          git commit -a -m "$commit_msg"

      - name: Push JS Config Changes To Gitee
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GE_TOKEN }}
          repository: ${{ secrets.GE_PATH }}
          directory: .
          branch: js
          force: true
          github_url: https://gitee.com
        env:
          GITHUB_ACTOR: ${{ secrets.GH_ACTOR }}

      - name: Push JS Config Changes To Github
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GH_TOKEN }}
          repository: ${{ secrets.GH_PATH }}
          directory: .
          branch: js
          force: true
        env:
          GITHUB_ACTOR: ${{ secrets.GH_ACTOR }}

      - name:  Build NodeJS Config files
        run: |
          rm -r ./code
          cp -r ./tmp ./code
          cd code/
          python build.py --aliToken "${{ secrets.ALI_TOKEN }}" --biliCookie "${{ secrets.BILI_COOKIE}}"
          cd nodejs
          npm install qs --save
          npm install tunnel  --save
          npm install 
          npm run build

      - name: Commit NodeJS Config files
        run: |
          git config --global user.email "${{ secrets.GT_EMAIL }}"
          git config --global user.name "${{ secrets.GT_ACTOR }}"
          checkname=$(git rev-list --max-parents=0 HEAD)
          git checkout  $checkname -b dist  ##分支不存在用这个
          cp -r code/nodejs/dist/* ./
          cp -r code/nodejs/readme.md ./README.md
          git add index.config.js
          git add index.config.js.md5
          git add index.js
          git add index.js.md5
          git add README.md
          commit_msg="* 发布 CatVodOpen新源"
          git commit -a -m "$commit_msg"

      - name: Push NodelJS Config Changes To Gitee
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GE_TOKEN }}
          repository: ${{ secrets.GE_PATH }}
          directory: .
          branch: dist
          force: true
          github_url: https://gitee.com
        env:
          GITHUB_ACTOR: ${{ secrets.GH_ACTOR }}

      - name: Push NodelJS Config Changes To Github
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GH_TOKEN }}
          repository: ${{ secrets.GH_PATH }}
          directory: .
          branch: dist
          force: true
        env:
          GITHUB_ACTOR: ${{ secrets.GH_ACTOR }}



      - name: Build 18+ NodeJS Config files
        run: |
          rm -r ./code
          cp -r ./tmp ./code
          cd code/
          python build.py --aliToken "${{ secrets.ALI_TOKEN }}" --biliCookie "${{ secrets.BILI_COOKIE}}"  --is_18 True
          cd  nodejs
          npm install qs --save
          npm install tunnel  --save
          npm install 
          npm run build

      - name: Commit 18+ NodeJS Config files
        run: |
          git config --global user.email "${{ secrets.GT_EMAIL }}"
          git config --global user.name "${{ secrets.GT_ACTOR }}"
          checkname=$(git rev-list --max-parents=0 HEAD)
          git checkout  $checkname -b 18_dist  ##分支不存在用这个
          cp -r code/nodejs/dist/* ./
          cp -r code/nodejs/readme.md ./README.md
          git add index.config.js
          git add index.config.js.md5
          git add index.js
          git add index.js.md5
          git add README.md
          commit_msg="* 发布 CatVodOpen 18+ 新源"
          git commit -a -m "$commit_msg"
      
      - name: Push NodelJS Config Changes To Gitee
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GE_TOKEN }}
          repository: ${{ secrets.GE_PATH }}
          directory: .
          branch: 18_dist
          force: true
          github_url: https://gitee.com
        env:
          GITHUB_ACTOR: ${{ secrets.GH_ACTOR }}

      - name: Push NodelJS Config Changes To Github
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GH_TOKEN }}
          repository: ${{ secrets.GH_PATH }}
          directory: .
          branch: 18_dist
          force: true
        env:
          GITHUB_ACTOR: ${{ secrets.GH_ACTOR }}

